package com.clpms.controller;

import com.clpms.bean.req.*;
import com.clpms.bean.resp.*;
import com.clpms.service.TeacherService;
import com.clpms.utils.ResultDto;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author caixinyong
 * @date 2023/5/1 4:56 PM
 */

@RestController
@RequestMapping("/teacher/v1")
@Slf4j
public class TeacherController {

	@Resource
	private TeacherService teacherService;

	//登录
	@PostMapping("/login")
	ResultDto<LoginResp> login(@RequestBody @Valid LoginReq req, HttpServletResponse response) {
		LoginResp resp = teacherService.login(req, response);
		return ResultDto.Success(resp);
	}

	//根据keyword查看员工信息
	@PostMapping("/queryTeacher")
	ResultDto<PageInfo<QueryTeacherResp>> queryTeacher(@RequestBody QueryTeacherReq req) {
		PageInfo<QueryTeacherResp> resp = teacherService.queryTeacher(req);
		return ResultDto.Success(resp);
	}

	//删除教师
	@PostMapping("/deleteTeacher")
	ResultDto<DeleteTeacherResp> deleteTeacher(@RequestBody @Valid DeleteTeacherReq req) {
		DeleteTeacherResp resp = teacherService.deleteTeacher(req);
		return ResultDto.Success(resp);
	}

	@PostMapping("/updateOrAdd")
	ResultDto<TeacherAddResp> updateOrAdd(@RequestBody @Valid TeacherAddReq req) {
		TeacherAddResp resp = teacherService.updateOrAdd(req);
		return ResultDto.Success(resp);
	}

	@PostMapping("/resetPassword")
	ResultDto<Boolean> resetPassword(@RequestBody @Valid ResetPasswordReq req) {
		Boolean result = teacherService.resetPassword(req);
		return ResultDto.Success(result);
	}

	@PostMapping("/changePassword")
	ResultDto<Boolean> changePassword(@RequestBody @Valid ChangePasswordReq req) {
		Boolean result = teacherService.changePassword(req);
		return ResultDto.Success(result);
	}
	@PostMapping("/overview")
	ResultDto<OverviewResp> overview(){
		OverviewResp resp = teacherService.overview();
		return ResultDto.Success(resp);
	}
}
